﻿using DotNetCore.CAP;
using Microsoft.AspNetCore.Mvc;
using MQCommon;
using MQCommon.Model;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace AggregateServices.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class CtreatOrderController : ControllerBase
    {
        // GET: api/<CtreatOrderController>
        private readonly ICapPublisher capPublisher;
        public CtreatOrderController(ICapPublisher capPublisher)
        {
            this.capPublisher = capPublisher;
        }
        [HttpGet]
        public IEnumerable<string> Get()
        {
            
            System.Random r = new Random();
            PayTime pt = new PayTime();
            pt.Id = r.Next(1, 10000);
            pt.Title = "test"+ pt.Id;
            pt.ctreattime=DateTime.Now;
            
            UserModel um=new UserModel();
            um.Id = r.Next(1, 10000);
            um.Name = "username"+ um.Id;
            um.ctreattime = DateTime.Now;
            um.des = "des";
            DapperHelper dh = new DapperHelper();
            dh.BeginTransaction(() => {
                IDictionary<string, string> dicHeader = new Dictionary<string, string>();
                dicHeader.Add("token", "123");
                capPublisher.Publish<PayTime>("order.payment", pt, dicHeader);
                IDictionary<string, string> dicHeaders = new Dictionary<string, string>();
                dicHeaders.Add("token", "123");
                capPublisher.Publish<UserModel>("order.ctreatUser", um, dicHeaders);
            }, capPublisher);
            return new string[] { "ok" };
        }

      
    }
}
